'use strict';
const qr = require('qr-image');
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('生成二维码 : ', event);
	let {queryStringParameters} = event;
	if (!queryStringParameters) {
		return {
			code: 500,
			msg: "不支持callFunction，请使用http请求方式调用"
		}
	}
	let {text} = queryStringParameters;
	if (!text) {
		return {
			code: 500,
			msg: "text不能为null"
		}
	}
	text = decodeURI(text);
	let code = qr.imageSync(text, {
		type: 'png',
		size: 10
	});
	let result = {
		"mpserverlessComposedResponse": true,
		"isBase64Encoded": true,
		"statusCode": 200,
		"headers": {
			"content-type": "image/png"
		},
		"body": code
	}
	return result;
};
